﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Regions;
using BlueMarble.Genesis.Common.Home;
using BlueMarble.Genesis.Common.About;

namespace BlueMarble.Genesis.Common
{
    public class CommonModule : IModule
    {
        private readonly IUnityContainer container;
        private readonly IRegionManager regionManager;

        public CommonModule(IUnityContainer container, IRegionManager regionManager)
        {
            this.container = container;
            this.regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterViewsAndServices();

            this.regionManager.RegisterViewWithRegion("MainTabRegion",
                () => this.container.Resolve<IHomeViewModel>().View);

            this.regionManager.RegisterViewWithRegion("MainTabRegion",
                () => this.container.Resolve<IAboutViewModel>().View);
        }

        protected void RegisterViewsAndServices()
        {
            this.container.RegisterType<IHomeViewModel, HomeViewModel>();
            this.container.RegisterType<IHomeView, HomeView>();

            this.container.RegisterType<IAboutViewModel, AboutViewModel>();
            this.container.RegisterType<IAboutView, AboutView>();
        }

        #endregion

    }
}
